$(function(){
	//菜单链接事件绑定
	$('a[flag="menu"]').map(function(){
		$(this).attr('onmouseover','omover(this)');
		$(this).attr('onmouseout','omout(this)');
		$(this).attr('onclick','onc(this);return false');
	});
	$('.img_cls_add').map(function(){
		$(this).attr('title','添加到常用菜单');
	});
	$('.img_cls_del').map(function(){
		$(this).attr('title','从常用菜单移除');
	});
});

function changeModule(){
	$('#reUrl').val($('#urlModule').val());
}

/**
 * 时间自动更新
 */
var startTime = function(){
	//获取当前系统日期  
    var today=new Date();  
    var year = today.getFullYear();       //年
    var month = today.getMonth() + 1;     //月
    var day = today.getDate();            //日
    var h=today.getHours();  
    var m=today.getMinutes();  
    var s=today.getSeconds();  
    //调用checkTime（）函数，小于十的数字前加0  
    m=checkTime(m);  
    s=checkTime(s);  
    $('#time').html(year + "-" + month + "-" + day + " "+ h +":"+ m +":"+ s);  
    //过500毫秒再调用一次  
    t=setTimeout('startTime()',500);  
    //小于10，加0  
    function checkTime(i)  
    {  
        if(i<10)  
           {i="0"+i;}  
        return i;  
    }  	
};

var omover = function(_this){
	$(_this).css('color','red');
};


var omout = function(_this){
	if($(_this).attr('ck') != 'yes'){
		$(_this).css('color','#8AA6FC');
		$(_this).next('span').hide();
	}
};

var onc = function(_this){
	$('a[flag="menu"]').map(function(){
		$(this).attr('ck','no');
		$(this).css('color','#8AA6FC');
		$(this).next('span').hide();
	});
	$(_this).attr('ck','yes');
	$(_this).css('color','red');
	$(_this).next('span').show();
	//进入对应的主页面
	intoPage(_this);
};

/***
 * 主页面入口
 * ***/
var intoPage = function(_this){
	if ($('#tt').tabs('exists', $(_this).html())){
		$('#tt').tabs('select',$(_this).html());
		$('#tt').tabs('update',{
			tab:$('#tt').tabs('getSelected'),
			options:{
				cache:false,
				height:'auto',
				title: $(_this).html(),
				content:createFrame($(_this).attr('link_url')),   
				closable: true
			}
		});
	}else{
		 $('#tt').tabs('add',{
			    cache:false,
			    height:'auto',
				title: $(_this).html(),
				content:createFrame($(_this).attr('link_url')),   
			    closable:true
			});
	}
};

var createFrame = function(url){
	return '<iframe frameborder="no" scrolling="auto" src="'+url+'" noresize="noresize" style="width: 100%; height: 100%; overflow: hidden;marginwidth:0px;marginheight:0px;"></iframe>';
};

/**
 * 重置搜索栏
 */
function clearForm(){
	$('#search_form')[0].reset();
}

/**
 * 配置搜索
 */
function submitSearch(){
	initSearch();
}

function initSearch(){
	var params = {};
	if($('#param').val() != null ){
		params = jQuery.parseJSON($('#param').val());
	}
	$.ajax({
		url : $('#reUrl').val(),
		type : $('#type').val(),
		dataType: 'json',
		data : params,
		success : function(data) {
			$('#data_table').html(JSON.stringify(data));
		},
		error : function(data) {
			$('#data_table').html(JSON.stringify(data));
		}
	});
}

function Serialize(obj) {  
    switch (obj.constructor) {  
    case Object:  
        var str = "{";  
        for ( var o in obj) {  
            str += o + ":" + Serialize(obj[o]) + ",";  
        }  
        if (str.substr(str.length - 1) == ",")  
            str = str.substr(0, str.length - 1);  
        return str + "}";  
        break;  
    case Array:  
        var str = "[";  
        for ( var o in obj) {  
            str += Serialize(obj[o]) + ",";  
        }  
        if (str.substr(str.length - 1) == ",")  
            str = str.substr(0, str.length - 1);  
        return str + "]";  
        break;  
    case Boolean:  
        return "\"" + obj.toString() + "\"";  
        break;  
    case Date:  
        return "\"" + obj.toString() + "\"";  
        break;  
    case Function:  
        break;  
    case Number:  
        return "\"" + obj.toString() + "\"";  
        break;  
    case String:  
        return "\"" + obj.toString() + "\"";  
        break;  
    }  
}  

function submitBhData(){
	var className = $('#className').val();
	var dbUrl = $('#dbUrl').val();
	var userName = $('#userName').val();
	var password = $('#password').val();
	$.ajax({
		url : base+'/daizy/db/betchTeacherConter/actionStart.action',
		type : 'post',
		dataType: 'json',
		data : {
			dbClassName:className,
			dbUrl:dbUrl,
			dbUserName:userName,
			dbPassword:password},
		success : function(data) {
			$('#data_table').html(JSON.stringify(data));
		},
		error : function(data) {
			$('#data_table').html(JSON.stringify(data));
		}
	});
}

//用户数据
function batchUserInfoStart(){
	var className = $('#className').val();
	var dbUrl = $('#dbUrl').val();
	var userName = $('#userName').val();
	var password = $('#password').val();
	$.ajax({
		url : base+'/daizy/db/batchUserInfo/batchUserInfoStart.action',
		type : 'post',
		dataType: 'json',
		data : {
			dbClassName:className,
			dbUrl:dbUrl,
			dbUserName:userName,
			dbPassword:password},
		success : function(data) {
			$('#data_table').html(JSON.stringify(data));
		},
		error : function(data) {
			$('#data_table').html(JSON.stringify(data));
		}
	});
}

//刷新徐州老用户redis
function batchSyncRedis(){
	var dbUrl = $('#dbUrl').val();
	var userName = $('#userName').val();
	var password = $('#password').val();
	var fairDbUrl = $('#fairDbUrl').val();
	var fairUserName = $('#fairUserName').val();
	var fairPassword = $('#fairPassword').val();
	var redisUrl = $('#redisUrl').val();
	var redisPort = $('#redisPort').val();
	$.ajax({
		url : base+'/hankai/db/batchSyncRedis.action',
		type : 'GET',
		dataType: 'json',
		data : {
			dsUrl:dbUrl,
			userName:userName,
			userPwd:password,
			fairUrl:fairDbUrl,
			fairUserName:fairUserName,
			fairUserPwd:fairPassword,
			redisUrl:redisUrl,
			redisPort:redisPort},
		success : function(data) {
			$('#data_table').html(JSON.stringify(data));
		},
		error : function(data) {
			$('#data_table').html(JSON.stringify(data));
		}
	});
}